package com.web.dao;

import com.github.pagehelper.Page;
import com.web.controller.web.WebCarouselController;
import com.web.entity.Carousel;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author FDjavaone
 */
public interface CarouselMapper {


    @Delete({
            "delete from t_carousel",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into t_carousel (type, store_name, ",
            " goods_picture, activity_picture, ",
            " activity_name, activity_url, ",
            " status, create_time, ",
            " modify_time)",
            " values (#{type,jdbcType=VARCHAR}, #{storeName,jdbcType=VARCHAR}, ",
            " #{goodsPicture,jdbcType=VARCHAR}, #{activityPicture,jdbcType=VARCHAR}, ",
            " #{activityName,jdbcType=VARCHAR}, #{activityUrl,jdbcType=VARCHAR}, ",
            " #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ",
            " #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insert(Carousel record);

    @InsertProvider(type = CarouselSqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insertSelective(Carousel record);


    @Select({
            "select",
            " id, type, store_name, goods_picture, activity_picture, activity_name, activity_url, ",
            " status, create_time, modify_time",
            " from t_carousel",
            " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "type", property = "type", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_name", property = "storeName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "goods_picture", property = "goodsPicture", jdbcType = JdbcType.VARCHAR),
            @Result(column = "activity_picture", property = "activityPicture", jdbcType = JdbcType.VARCHAR),
            @Result(column = "activity_name", property = "activityName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "activity_url", property = "activityUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    Carousel selectByPrimaryKey(Long id);


    @UpdateProvider(type = CarouselSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Carousel record);

    @Update({
            "update t_carousel",
            " set type = #{type,jdbcType=VARCHAR},",
            " store_name = #{storeName,jdbcType=VARCHAR},",
            " goods_picture = #{goodsPicture,jdbcType=VARCHAR},",
            " activity_picture = #{activityPicture,jdbcType=VARCHAR},",
            " activity_name = #{activityName,jdbcType=VARCHAR},",
            " activity_url = #{activityUrl,jdbcType=VARCHAR},",
            " status = #{status,jdbcType=INTEGER},",
            " create_time = #{createTime,jdbcType=TIMESTAMP},",
            " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Carousel record);

    @Select({
            "select",
            " id, type, store_name, goods_picture, activity_picture, activity_name, activity_url, ",
            " status, create_time, modify_time",
            " from t_carousel",
            " where status = '1'"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "type", property = "type", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_name", property = "storeName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "goods_picture", property = "goodsPicture", jdbcType = JdbcType.VARCHAR),
            @Result(column = "activity_picture", property = "activityPicture", jdbcType = JdbcType.VARCHAR),
            @Result(column = "activity_name", property = "activityName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "activity_url", property = "activityUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    List<Carousel> selectActivity();


    @SelectProvider(type = CarouselSqlProvider.class, method = "selectAllCarousel")
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "type", property = "type", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_name", property = "storeName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "goods_picture", property = "goodsPicture", jdbcType = JdbcType.VARCHAR),
            @Result(column = "activity_picture", property = "activityPicture", jdbcType = JdbcType.VARCHAR),
            @Result(column = "activity_name", property = "activityName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "activity_url", property = "activityUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    Page<Carousel> selectAllCarousel(WebCarouselController.CarouselColumns carouselColumns);
}